package com.bgs.controller;

import com.bgs.entity.Store;
import com.bgs.pojo.CommodityorderVo;
import com.bgs.service.CommodityorderService;
import com.bgs.service.StoreService;
import com.bgs.tool.R;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/commodityorder")
public class CommodityorderController {
    @Autowired
    CommodityorderService commodityorderService;
    @Autowired
    StoreService storeService;
//    根据状态查询商品订单
    @GetMapping("load/{curNow}/{userId}")
    public R load(@PathVariable Integer curNow,@PathVariable Integer userId){
        List<CommodityorderVo> commodityorderVo =  commodityorderService.load(curNow,userId);
        return R.ok().data("arr",commodityorderVo);
    }
    //根据订单id查询订单信息
    @GetMapping("load2/{coId}")
    public R load2(@PathVariable Integer coId){
        List<CommodityorderVo> commodityorderVo =  commodityorderService.load2(coId);
        return R.ok().data("arr2",commodityorderVo);
    }
//    取消商品订单
    @GetMapping("qxdd/{coId}")
    public R qxdd(@PathVariable Integer coId){
        commodityorderService.qxdd(coId);
        return R.ok();
    }
//    查询订单信息
    @GetMapping("find/{coId}")
    public R find (@PathVariable Integer coId){
        Map<String,Object> map = new HashMap<>();
        CommodityorderVo commodityorderVo = commodityorderService.find(coId);
        List<Store> stores =  storeService.load2(commodityorderVo.getCoId());
        map.put("commodit",commodityorderVo);
        map.put("store",stores);
        return R.ok().data("data",map);
    }
    @GetMapping("updatecotype/{coId}")
    public R updatecotype (@PathVariable Integer coId){
        commodityorderService.updatecotype(coId);
        return R.ok();
    }
}